﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JBeamLibrary.Tools;
using JBeamLibrary.VehicleParts.Enums;
using JBeamLibrary.VehicleParts.Interfaces;
using Newtonsoft.Json.Linq;

namespace JBeamLibrary.VehicleParts.Elements
{
    public class HubWheel : VehicleElement
    {
        #region Properties

        public string Name { get; set; }

        public string Group { get; set; }

        public string NodeId1 { get; set; }

        public string NodeId2 { get; set; }

        public string NodeArmId { get; set; }

        public WheelDirection WheelDirection { get; set; }

        #endregion

        #region CTORs

        public HubWheel()
        {

        }

        public HubWheel(string name)
            : this()
        {
            Name = name;
        }

        public HubWheel(string name, string group, string id1, string id2, string armId, WheelDirection wheelDir)
            : this(name)
        {
            Group = group;
            NodeId1 = id1;
            NodeId2 = id2;
            NodeArmId = armId;
            WheelDirection = wheelDir;
        }

        #endregion

        #region Methods

        public override IVehicleElement FromJBeam(JToken token)
        {
            var arr = token as JArray;
            if (arr == null) return this;

            Name = token[0].FromJBeam<string>();
            Group = token[1].FromJBeam<string>();
            NodeId1 = token[2].FromJBeam<string>();
            NodeId2 = token[3].FromJBeam<string>();
            NodeArmId = token[5].FromJBeam<string>();
            WheelDirection = token[6].FromJBeam<WheelDirection>();

            return this;
        }

        public override JToken ToJBeam()
        {
            return new JArray
            {
                Name.ToJBeam(),
                Group.ToJBeam(),
                NodeId1.ToJBeam(),
                NodeId2.ToJBeam(),
                9999,
                NodeArmId.ToJBeam(),
                (int)WheelDirection
            };
        }

        public override string ToString()
        {
            return Name;
        }

        #endregion
    }
}
